package com.zxjbyte.yiyi.framework.common.core.eventbus;

import com.google.common.eventbus.EventBus;
import lombok.Data;
import lombok.Getter;

/**
 * 同步事件总线服务
 *
 * @Author zhangxingjia
 * @Date 2025/1/13 15:45
 * @Version: 1.0
 */
@Getter
public class EventBusService implements EventDispatcher{

    private EventBus eventBus;

    private EventBusService() {
    }

    /**
     * 创建同步事件总线
     * @return
     */
    public static EventBusService defaultService() {
        EventBusService eventBusService = new EventBusService();
        eventBusService.eventBus = new EventBus();
        return eventBusService;
    }

    @Override
    public void register(Object subscriber) {
        eventBus.register(subscriber);
    }

    @Override
    public void unregister(Object subscriber) {
        eventBus.unregister(subscriber);
    }

    @Override
    public void post(Object event) {
        eventBus.post(event);
    }

}
